package gui;

import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawable;
import javax.media.opengl.GLDrawableFactory;

import com.jogamp.newt.opengl.GLWindow;

import utilities.Constantes;

public class GameFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static GameFrame instence;
	
	private GLDrawable drawable; // the rendering 'surface'
	private GLContext context; // rendering state info
	private GLWindow window; //The window itself
	
	private volatile boolean requestedResize;
	
	public static GameFrame getInstance(){
		if(instence == null)
			instence = new GameFrame();
		return instence;
	}
	
	public GameFrame(){
		GLCapabilities caps = new GLCapabilities(Constantes.PROFILE);
		window = GLWindow.create(caps);
		window.setTitle("Proute");
		window.setVisible(true);
		window.addMouseListener(new MListener());
		window.addKeyListener(new KListener());
		//Creation of a buffer drawable so we paint in a buffer and then swap it with the screen in the
		//render manager 
		drawable = GLDrawableFactory.getFactory(Constantes.PROFILE).createGLDrawable(window);
		context = drawable.createContext(null);
		
		window.setSize(Constantes.FRAME_WIDTH,Constantes.FRAME_HEIGHT);
		window.addWindowListener(new GameFrameListener());
	}
	
	public GLContext getContext(){
		return context;
	}
	
	public GLDrawable getDrawable(){
		return drawable;
	}
	
	public int getWidth(){
		return window.getWidth();
	}
	
	public int getHeight(){
		return window.getHeight();
	}
	
	public boolean requestedResize(){
		return requestedResize;
	}
	
	public synchronized void setRequestResize(boolean r){
		this.requestedResize = r;
	}
}

